<?php

namespace App\Providers;

use Faker\Generator;
use Illuminate\Support\ServiceProvider;

class FakerServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton(\Faker\Generator::class, function($app) {
            $faker = \Faker\Factory::create();
            $faker->addProvider(new class($faker) extends \Faker\Provider\Base {
                private $storage;

                private $files;

                public function __construct(Generator $generator)
                {
                    $this->storage = \Illuminate\Support\Facades\Storage::disk('public');
                    $this->files = $this->storage->allFiles('images');
                    parent::__construct($generator);
                }
                public function avatar()
                {
                    return $this->storage->url(array_random($this->files));
                }
                public function logo()
                {
                    return $this->storage->path(array_random($this->files));
                }
            });
            return $faker;
        });
    }
}
